/**
 * create by young (young2f@outlook.com) on 2020/9/16
 * 选择辅料
 */


'use strict';
import React from 'react';
import {Button, Card, Descriptions, Form, InputNumber, notification, Tag} from 'antd';

import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

import {FormField, FormLayout, ModalFooter} from "antd-extra";
import notify from "../../../components/NotificationExtra";
import ViewTitle from "../../../components/ViewTitle";

const {Meta} = Card;

moment.locale('zh-cn');
const table = 'ProcureOrder';
@Form.create()
@connect(({
            user,
            global,
            dynamicLabel,
            material,
            store
          }) => ({...user, ...material, ...dynamicLabel, ...global, ...store}))
export default class ModalEditStoreCount extends FormBase {
  constructor(props) {
    super(props);
    this.state = undefined;
  }

  componentDidMount() {


  }

  renderFoot = () => {
    const {foot, value, modalRef, form, callback} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {
              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              callback(values);
              modalRef.close();
            });
          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };


  render() {
    const {style, values, form} = this.props;
    const {code, name, spec, type, number, storeCount = 0} = values;
    return (
      <div style={{...style}}>
        <Descriptions bordered size={'small'} column={2}>
          <Descriptions.Item label="物料编码">{code}</Descriptions.Item>
          <Descriptions.Item label="物料名称">{name}</Descriptions.Item>
          <Descriptions.Item label="物料规格">{spec}</Descriptions.Item>
          <Descriptions.Item label="物料类型">{type}</Descriptions.Item>
          <Descriptions.Item label="物料型号">{number}</Descriptions.Item>
          <Descriptions.Item label="现有库存">{storeCount}</Descriptions.Item>

        </Descriptions>
        <divider></divider>
<ViewTitle
title={'修改库存数量'}
></ViewTitle>
        {
          <FormLayout form={form}>
            <FormField
              label={'新库存数量'}
              name={'storeCount'}
              initialValue={storeCount}
            >
              <InputNumber style={{ width: '80%' }} >

              </InputNumber>
            </FormField>
          </FormLayout>
        }
        <div style={{color:'#f00'}}>调整库存数量会造成出入库数量错误，建议在物料初始化时操作，物料有出入库记录后不要操作！</div>
        {this.renderFoot()}
      </div>

    );
  }
}

